﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;

namespace ProjectStudy.Ajax
{
    /// <summary>
    /// 绑定listbox 的摘要说明
    /// </summary>
    public class 绑定listbox : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            string action = context.Request.Params["action"];

            if (!string.IsNullOrEmpty(action))
            {
                this.GetType().GetMethod(action).Invoke(this, new object[] { context });
            }
            return; 
        }

        public void GetProvince(HttpContext context)
        {
            string sql = "select ProvinceName from Province";
            DataTable dt= DBAccess.ExecuteDataTable(sql);
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            context.Response.Write(json);
        }

        public void GetCity(HttpContext context)
        {
            string sql = "select CityName from City where ProvinceName=@provincename";
            string provincename=context.Request["provincename"];
            SqlParameter ps = new SqlParameter("@provincename",provincename);
            DataTable dt = DBAccess.ExecuteDataTable(sql,ps);
            string json = Newtonsoft.Json.JsonConvert.SerializeObject(dt);
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}